/**
 * Copyright (c) 2020 Coder League
 * All rights reserved.
 *
 * File：FileUploadController.java
 * History:
 *         2020年12月20日: Initially created, Chrise.
 */
package club.coderleague.cfss.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import club.coderleague.cfss.annotations.Request;
import club.coderleague.cfss.config.properties.FileUploadSettings;
import club.coderleague.cfss.util.FileUtil;

/**
 * 文件上传控制器。
 * @author Chrise
 */
@Controller
@RequestMapping(IndexController.REQUEST_PREFIX + "/fileupload")
public class FileUploadController extends IndexController {
	@Autowired
	private FileUploadSettings fuSettings;
	
	/**
	 * 上传系统配置文件。
	 * @author Chrise 2020年12月20日
	 * @param request HTTP请求对象。
	 * @return 上传结果。
	 * @throws Exception 上传错误。
	 */
	@ResponseBody
	@RequestMapping("/uploadthesystemfiles.xhtml")
	@Request(value = "上传系统配置文件")
	public ModelMap uploadTheSystemFiles(HttpServletRequest request) throws Exception {
		List<MultipartFile> files = ((MultipartHttpServletRequest)request).getFiles("file");
		FileUtil.saveSystemFiles(files, this.fuSettings.getRootReal());
		return super.createModel(true);
	}
}
